# The template for the spot controller

name: {{dag_name}}

file_mounts:
  {{remote_user_yaml_path}}: {{user_yaml_path}}
  {{remote_user_config_path}}: skypilot:local_skypilot_config_path

setup: |
  {%- for cmd in cloud_dependencies_installation_commands %}
  {{cmd}}
  {%- endfor %}

  {% if is_dev %}
  # Internal: disable logging for manually logging into the spot controller for debugging.
  echo 'export SKYPILOT_DEV=1' >> ~/.bashrc
  {% endif %}

  # Dashboard.
  pip list | grep flask  > /dev/null 2>&1 || pip install flask 2>&1 > /dev/null
  ((ps aux | grep -v nohup | grep -v grep | grep -q -- "python3 -m sky.spot.dashboard.dashboard") || (nohup python3 -m sky.spot.dashboard.dashboard >> ~/.sky/spot-dashboard.log 2>&1 &));

run: |
  # Start the controller for the current spot job.
  python -u -m sky.spot.controller {{remote_user_yaml_path}} \
    --job-id $SKYPILOT_INTERNAL_JOB_ID {% if retry_until_up %}--retry-until-up{% endif %}

envs:
{%- for env_name, env_value in controller_envs.items() %}
  {{env_name}}: {{env_value}}
{%- endfor %}
